﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XiaonuanPMS.Entity;
using DevicesView.Logic;
using DevicesView.Logic.App;
using Newtonsoft.Json;
using XiaonuanPMS.Entity.Request;
using Devices;
using DevicesView.Entity;
using XiaonuanPMS.Entity.View;
using DevicesView.Logic.Print;
using System.Windows.Media.Imaging;
using System.IO;
using DevicesView.UCControl;
using DevicesView;

namespace XiaonuanPMS.Logic
{
    public class TestingsLogic
    {
        private static string httpAdd = "";
        //private static Dictionary<string, string> staticData;
        private static RuiPaiUser LoginUser;
        //private static RuiPaiPMSOrgInfo LoginOrg;

        public static List<Doctor> Doctors { get; set; }

        static TestingsLogic()
        {
            httpAdd = AppResource.CurrentResource.NetConfig.Servers.FirstOrDefault(o => o.ServerName == "XiannuanWebServer").Address;


        }


        /// <summary>
        /// 准备缓存数据  包括医生及医院信息
        /// </summary>
        /// <param name="orgcode"></param>
        private void GetStaticData(string orgcode)
        {
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/getDoctorsInfo?orgCode=" + orgcode, Method = HttpMethod.Get };
            hi.Url += "&access_token=" + LoginUser.access_token;
            //hi.Headers.Add("access_token: " + LoginUser.access_token);



            HttpResult<RuipaiEntityBase<List<RPDoctor>>> httpresultdoct = WebLogic.GetHttpResult<RuipaiEntityBase<List<RPDoctor>>>(hi);
            if (httpresultdoct.Success && httpresultdoct.Result?.code == "0" && httpresultdoct.Result?.data != null)
            {
                List<Doctor> doctors = new List<Doctor>();
                foreach (var item in httpresultdoct.Result?.data)
                    doctors.Add(new Doctor { Id = item.code, Code = item.code, Name = item.name, OrgCode = item.orgCode, PhoneNumber = item.phoneNumber });
                AppResource.CurrentResource.Doctors = Doctors = doctors;
            }


            if (AppResource.CurrentResource.Hospital == null)
                AppResource.CurrentResource.Hospital = new HospitalInfo();
            HospitalInfo hinfo = AppResource.CurrentResource.Hospital;

            hi = new HttpItem { Url = httpAdd + "platform/lisapi/getDeptInfo?orgCode=" + orgcode, Method = HttpMethod.Get };
            hi.Url += "&access_token=" + LoginUser.access_token;
            //hi.Headers.Add("access_token: " + LoginUser.access_token);
            HttpResult<RuipaiEntityBase<RuiPaiPMSOrgInfo>> httpresultorg = WebLogic.GetHttpResult<RuipaiEntityBase<RuiPaiPMSOrgInfo>>(hi);
            if (httpresultorg.Success && httpresultorg.Result != null && httpresultorg.Result?.code == "0")
            {
                RuiPaiPMSOrgInfo org = httpresultorg.Result.data;
                hinfo.Code = org.id.ToString();
                hinfo.Name = org.orgname;
                hinfo.Phone = org.Telephone;
                hinfo.Address = org.Address;
            }
            else
            {
                hinfo.Code = orgcode;
                hinfo.Name = "未获取";
            }
        }

        /// <summary>
        /// 获取当前所有检查信息
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<TestInfoSource> GetTestInfos(DateTime startTime, DateTime endTime)
        {
            var dy = new { orgid = AppResource.CurrentResource.Hospital.Code, startTime, endTime };
            string param = string.Format("?orgCode={0}&start={1}&end={2}",
                AppResource.CurrentResource.Hospital.Code,
                startTime.ToString("yyyy-MM-dd"),
                endTime.ToString("yyyy-MM-dd")
                );
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/laboratoryRecordList" + param, Method = HttpMethod.Get };
            hi.Url += "&access_token=" + LoginUser.access_token;
            //hi.Headers.Add("access_token:" + LoginUser.access_token);


            HttpResult<RuipaiEntityBase<List<RPTestInfo>>> httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<List<RPTestInfo>>>(hi);
            if (!httpResult.Success || httpResult.Result == null || httpResult.Result.code != "0" || httpResult.Result.data == null)
                return null;
            DateTime dt = new DateTime();

            var datas = httpResult.Result.data.OrderByDescending(o => DateTime.TryParse(o.reportingDate, out dt) ? dt.Ticks : 0);

            List<TestInfoSource> tests = new List<TestInfoSource>();
            foreach (var item in datas)
            {
                tests.Add(new TestInfoSource
                {
                    CustomerID = item.customerId,
                    CustomerName = item.customerName,
                    id = item.reportId,
                    PetId = item.petId,
                    PetName = item.petName,
                    ReportId = item.reportId,
                    ReportName = item.reportName,
                    PhysicianId = item.physicianId,
                    PhysicianName = item.physicianName,
                    ReportingDate = item.reportingDate,
                    Version = item.version
                });
            }

            List<Devices.Command> cmds = Devices.DevicesCollection.Commands;
            DevicesView.Logic.Test.ResultLogic resultLogic = new DevicesView.Logic.Test.ResultLogic();
            List<Result> completed = resultLogic.Completed;
            if (cmds != null)
                tests.ForEach(o =>
                {
                    o.CMD = cmds.FirstOrDefault(cmd => cmd.Id == o.ReportId);
                    o.Send = o.CMD == null ? 0 : 1;
                    if (o.CMD == null && completed != null)
                    {
                        Result result = completed.FirstOrDefault(cmp => cmp.CMD.Id == o.ReportId);
                        if (result != null)
                        {
                            o.CMD = result.CMD;
                            o.Send = 2;
                            o.Devices = 3;
                        }
                    }
                });

            return tests;
        }

        public List<TestingResult> GetTestDetails(string ReportId)
        {
            httpAdd = AppResource.CurrentResource.NetConfig.Servers.FirstOrDefault(o => o.ServerName == "XiannuanWebServer")?.Address;
            HttpItem hi = new HttpItem { Url = httpAdd + "invoke/testdetails", Method = HttpMethod.Post, ContentType = "text/plain" };
            hi.ContentObject = new BaseRequest { orgid = AppResource.CurrentResource.Hospital.Code, param = ReportId };
            HttpResult<List<TestingResult>> httpResult = WebLogic.GetHttpResult<List<TestingResult>>(hi);
            if (httpResult.Success)
                return httpResult.Result;
            return null;
        }

        /// <summary>
        /// 获取宠物信息
        /// </summary>
        /// <param name="reportId"></param>
        /// <returns></returns>
        public RPTestPetInfo GetTestPet(string reportId)
        {
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/petInfo?petId=" + reportId, Method = HttpMethod.Get };
            hi.Url += "&access_token=" + LoginUser.access_token;
            //hi.Headers.Add("access_token:" + LoginUser.access_token);
            HttpResult<RuipaiEntityBase<RPTestPetInfo>> httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<RPTestPetInfo>>(hi);

            if (!httpResult.Success || httpResult.Result == null || httpResult.Result.code != "0")
                return null;
            return httpResult.Result.data;
        }


        /// <summary>
        /// 获取宠物信息
        /// </summary>
        /// <param name="reportId"></param>
        /// <returns></returns>
        public string EditPetInfo(editPetInfo petinfo)
        {
            string msg = "";
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/editPetInfo", Method = HttpMethod.Post, ContentType = "application/json; charset=utf-8" };
            hi.Url += "?access_token=" + LoginUser.access_token;
            hi.ContentObject = petinfo;
            hi.Content = JsonConvert.SerializeObject(petinfo).GetBytes(Encoding.UTF8);
            HttpResult<RuipaiEntityBase<object>>  httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<object>>(hi);

            if (!httpResult.Success || httpResult.Result == null || httpResult.Result.code != "0")
                msg= httpResult?.Message;
            return msg;
        }


        /// 获取宠物种类数据字典
        public List<RPDataDic> GetPetType()
        {
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/basicCodePetType", Method = HttpMethod.Get };
            hi.Url += "?access_token=" + LoginUser.access_token;
            HttpResult<RuipaiEntityBase<List<RPDataDic>>> httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<List<RPDataDic>>>(hi);
            if (httpResult.Success && httpResult.Result?.code == "0")
                return httpResult.Result.data;
            return null;
        }

        /// 获取宠物品种数据字典
        public RPResult GetPetBreed()
        {
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/basicCodePetBreed", Method = HttpMethod.Get };
            hi.Url += "?access_token=" + LoginUser.access_token;
            HttpResult<RuipaiEntityBase<RPResult>> httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<RPResult>>(hi);
            if (httpResult.Success && httpResult.Result?.code == "0")
                return httpResult.Result.data;
            return null;
        }

        /// 获取宠物性别数据
        public List<RPDataDic> GetPetSex()
        {
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/basicCodePetSex", Method = HttpMethod.Get };
            hi.Url += "?access_token=" + LoginUser.access_token;
            HttpResult<RuipaiEntityBase<List<RPDataDic>>> httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<List<RPDataDic>>>(hi);
            if (httpResult.Success && httpResult.Result?.code == "0")
                return httpResult.Result.data;
            return null;
        }

        //public Dictionary<string, string> StaticData { get { return staticData; } }

        /// <summary>
        /// 获取当前用户的所有机构
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public List<RuiPaiPMSOrgInfo> GetOrgs(string loginName)
        {
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/getUserDepts?loginName=" + loginName, Method = HttpMethod.Get };
            HttpResult<RuipaiEntityBase<List<RuiPaiPMSOrgInfo>>> httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<List<RuiPaiPMSOrgInfo>>>(hi);
            if (httpResult.Success && httpResult.Result?.code == "0")
                return httpResult.Result.data;
            return null;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pass"></param>
        /// <param name="orgcode"></param>
        /// <param name="remember"></param>
        /// <returns></returns>
        public string Login(string name, string pass, string orgcode, bool remember)
        {
            var dy = new { loginName = name, password = pass, orgCode = orgcode };
            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/login", Method = HttpMethod.Post, ContentType = "application/json; charset=utf-8" };
            hi.Content = JsonConvert.SerializeObject(dy).GetBytes(UTF8Encoding.UTF8);
            HttpResult<RuipaiEntityBase<RuiPaiUser>> httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<RuiPaiUser>>(hi);
            if (!httpResult.Success)
                return httpResult.Message;
            if (httpResult.Result == null)
                return "请求服务器失败";
            if (httpResult.Result.code != "0")
                return string.IsNullOrEmpty(httpResult.Result.msg) ? "服务器错误" : httpResult.Result.msg;

            if (httpResult.Result.data == null)
                return string.IsNullOrEmpty(httpResult.Result.msg) ? "服务器错误" : httpResult.Result.msg;

            LoginUser = httpResult.Result.data;

            UserConfig user = new UserConfig { LoginName = name, Password = pass, LoginOrgId = orgcode, UserId = LoginUser.userCode, Remember = remember };
            user.Save();

            SystemUserInfo info = new SystemUserInfo { Password = user.Password, Id = LoginUser.userCode, OrgCode = orgcode, UserCode = LoginUser.userCode, UserName = LoginUser.userName, LoginName = name, Phone = LoginUser.phone, Address = LoginUser.address };
            AppResource.CurrentResource.LoginUser = info;
            AppResource.CurrentResource.Save();
            GetStaticData(orgcode);
            return "";
        }

        /// <summary>
        /// 保存检查结果
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        public bool SaveResult(Command cmd)
        {
            //RPResult result = new RPResult {Date = cmd.Result.Date, ResultDatas = cmd.Result.ResultDatas };123
            // 结果分析初始化
            string remarks = "无";
            // 结果分析-判空处理
            if (cmd.Result != null) {
                if (cmd.Result.Remarks != null && cmd.Result.Remarks.Count > 0) {
                    remarks = cmd.Result.Remarks[0];
                }
            }
            RPResult result = new RPResult { };
            result.laboratoryRecord = new RPLaboratoryRecord
            {
                version = Convert.ToInt64(cmd.Tag),
                id = long.Parse(cmd.Id),
                inspectionResultTime = cmd.Result.Date.ToString("yyyy-MM-dd HH:mm:ss"),
                operatorId = cmd.OperatorCode,
                // 结果分析
                resultAnalysis = remarks

            };


            result.machineInfo = new RpMachineInfo { id = cmd.Info.Num, brand = cmd.Info.Brand, code = cmd.Info.Code, name = cmd.Info.Name, num = cmd.Info.Num.ToString(), model = cmd.Info.Model, displayName = cmd.Info.DisplayName };
            result.resultDatas = new List<RpResultData>();
            foreach (ResultItem item in cmd.Result.ResultDatas)
            {
                result.resultDatas.Add(new RpResultData
                {
                    code = item.Code,
                    display = item.Display,
                    englishName = item.EnglishName,
                    unit = item.Unit,
                    max = item.Max,
                    min = item.Min,
                    name = item.Name,
                    value = item.Value?.ToString()
                });
            }

            HttpItem hi = new HttpItem { Url = httpAdd + "platform/lisapi/saveLaboratoryRecordResult", Method = HttpMethod.Post, ContentType = "application/json; charset=utf-8" };
            hi.Url += "?access_token=" + LoginUser.access_token;
            string json = JsonConvert.SerializeObject(result);
            hi.Content = json.GetBytes(UTF8Encoding.UTF8);
            HttpResult<RuipaiEntityBase<object>> httpResult = WebLogic.GetHttpResult<RuipaiEntityBase<object>>(hi);

            if (httpResult.Success && httpResult.Result?.code == "0")
            {
                //保存结果到LIS服务器
                DevicesView.Logic.Test.ResultLogic.SaveResult(cmd.Result);
                //异步上传打印文件
                System.Threading.Tasks.Task.Run(() => PutPDF(cmd));
                return true;
            }
            return false;
        }


        /// <summary>
        /// 保存机器的打印模板为PDF，并上传到OBS
        /// </summary>
        /// <param name="cmd"></param>
        private void PutPDF(Command cmd)
        {
            if (!(PrintLogic.GetPrintConfig(cmd.Info) is IPrintExpand pe))
                return;
            Stream sm = pe.PrintToPDF(new List<Result>() { cmd.Result });
            DevicesView.Logic.Oss.HuaweiOBS.CreateAliOSS().Put("lis/" + cmd.Info.Code + "/" + cmd.Id, sm);
        }

    }

    public class RuipaiYicong
    {
        private string Code { get; set; }

        private string Name { get; set; }

        private int kindOfType
        {
            get; set;
        }


        private static List<RuipaiYicong> lists;
        static RuipaiYicong()
        {
            lists = new List<RuipaiYicong>();
            lists.Add(new RuipaiYicong { Code = "100", Name = "大鼠", kindOfType = 4 });
            lists.Add(new RuipaiYicong { Code = "101", Name = "小鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "9", Name = "仓鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "15", Name = "豚鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "17", Name = "鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "39", Name = "小松鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "41", Name = "天竺鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "60", Name = "魔王松鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "75", Name = "花枝鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "85", Name = "松鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "3", Name = "龙猫", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "94", Name = "土拨鼠", kindOfType = 5 });
            lists.Add(new RuipaiYicong { Code = "42", Name = "龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "0", Name = "乌龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "19", Name = "草龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "37", Name = "巴西龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "43", Name = "北美拟鳄龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "44", Name = "海龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "46", Name = "鲍龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "59", Name = "福德龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "61", Name = "缅甸陆龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "62", Name = "象龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "66", Name = "长寿龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "70", Name = "泽龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "76", Name = "鳄龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "77", Name = "金钱龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "82", Name = "陆龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "87", Name = "苏卡达", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "89", Name = "红腿陆龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "90", Name = "苏卡达陆龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "91", Name = "剃刀龟", kindOfType = 14 });
            lists.Add(new RuipaiYicong { Code = "6", Name = "兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "11", Name = "熊猫兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "12", Name = "海棠兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "13", Name = "垂耳兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "22", Name = "侏儒兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "23", Name = "猫猫兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "25", Name = "长毛兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "26", Name = "狮子兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "27", Name = "西施兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "28", Name = "肉兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "31", Name = "折耳兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "32", Name = "家兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "51", Name = "英国迷你折耳兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "58", Name = "凤眼侏儒", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "54", Name = "道奇兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "72", Name = "安哥拉兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "79", Name = "长耳兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "97", Name = "荷兰兔", kindOfType = 6 });
            lists.Add(new RuipaiYicong { Code = "7", Name = "鸟", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "14", Name = "鹦鹉", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "49", Name = "非洲灰鹦鹉", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "53", Name = "虎皮鹦鹉", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "56", Name = "金刚琉璃鹦鹉", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "63", Name = "玄凤鹦鹉", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "64", Name = "灰鹦鹉", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "65", Name = "葵花鹦鹉", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "24", Name = "鸽子", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "40", Name = "信鸽", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "68", Name = "猫头鹰", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "45", Name = "小麻雀", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "78", Name = "喜鹊", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "1", Name = "鹰", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "80", Name = "鸵鸟", kindOfType = 21 });
            lists.Add(new RuipaiYicong { Code = "30", Name = "猪", kindOfType = 9 });
            lists.Add(new RuipaiYicong { Code = "10", Name = "荷兰猪", kindOfType = 9 });
            lists.Add(new RuipaiYicong { Code = "34", Name = "香猪", kindOfType = 9 });
            lists.Add(new RuipaiYicong { Code = "93", Name = "猪鼻蛇", kindOfType = 9 });
            lists.Add(new RuipaiYicong { Code = "20", Name = "虎", kindOfType = 17 });
            lists.Add(new RuipaiYicong { Code = "5", Name = "牛蛙", kindOfType = 28 });
            lists.Add(new RuipaiYicong { Code = "88", Name = "树蛙", kindOfType = 18 });
            lists.Add(new RuipaiYicong { Code = "92", Name = "角蛙", kindOfType = 18 });
            lists.Add(new RuipaiYicong { Code = "8", Name = "蜥蜴", kindOfType = 15 });
            lists.Add(new RuipaiYicong { Code = "71", Name = "鬃狮蜥", kindOfType = 15 });
            lists.Add(new RuipaiYicong { Code = "73", Name = "豹纹守宫", kindOfType = 15 });
            lists.Add(new RuipaiYicong { Code = "67", Name = "绿鬣蜥", kindOfType = 15 });
            lists.Add(new RuipaiYicong { Code = "16", Name = "貂", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "33", Name = "雪貂", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "18", Name = "羊驼", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "21", Name = "鸡", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "29", Name = "狐狸", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "35", Name = "刺猬", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "36", Name = "贝灵缇", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "48", Name = "猴", kindOfType = 7 });
            lists.Add(new RuipaiYicong { Code = "47", Name = "蜂猴", kindOfType = 8 });
            lists.Add(new RuipaiYicong { Code = "52", Name = "拇指猴", kindOfType = 9 });
            lists.Add(new RuipaiYicong { Code = "81", Name = "长尾猴", kindOfType = 10 });
            lists.Add(new RuipaiYicong { Code = "50", Name = "浣熊", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "55", Name = "鹅", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "57", Name = "蜜袋鼯", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "74", Name = "鱼", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "83", Name = "金丝熊", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "95", Name = "梅花鹿", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "96", Name = "鸭子", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "84", Name = "其他", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "86", Name = "其他类", kindOfType = 100 });
            lists.Add(new RuipaiYicong { Code = "99", Name = "马", kindOfType = 3 });
            lists.Add(new RuipaiYicong { Code = "105", Name = "奶牛", kindOfType = 8 });
            lists.Add(new RuipaiYicong { Code = "106", Name = "水牛", kindOfType = 10 });
            lists.Add(new RuipaiYicong { Code = "107", Name = "骆驼", kindOfType = 11 });
            lists.Add(new RuipaiYicong { Code = "108", Name = "绵羊", kindOfType = 12 });
            lists.Add(new RuipaiYicong { Code = "38", Name = "山羊", kindOfType = 13 });
            lists.Add(new RuipaiYicong { Code = "109", Name = "狮子", kindOfType = 16 });
            lists.Add(new RuipaiYicong { Code = "102", Name = "东北虎", kindOfType = 17 });
            lists.Add(new RuipaiYicong { Code = "103", Name = "孟加拉虎", kindOfType = 18 });
            lists.Add(new RuipaiYicong { Code = "104", Name = "美洲狮", kindOfType = 19 });
            lists.Add(new RuipaiYicong { Code = "4", Name = "蛇", kindOfType = 20 });
        }

        public static KindOfType GetKindOfType(string code)
        {
            if (string.IsNullOrEmpty(code))
                return KindOfType.犬;
            RuipaiYicong yicong = lists.FirstOrDefault(o => o.Code == code);
            return yicong == null ? KindOfType.其它 : (KindOfType)yicong.kindOfType;
        }

    }


    public class editPetInfo
    {
        public string id { get; set; }//": 11,//宠物id long
        public string ageYear { get; set; }//": 1,//宠物年龄 岁 int
        public string ageMonth { get; set; }//": 1,//宠物年龄 月 int
        public string ageDay { get; set; }//": 1,//宠物年龄 天 int
        public string weight { get; set; }//": "体重 (kg) string",
        public string petType { get; set; }//": "种类 宠物种类数据字典中的codeValue string",
        public string petBreed { get; set; }//": "品种 宠物品种数据字典中的codeValue string",
        public string petSex { get; set; }//": "性别 宠物性别数据字典中的codeValue string",

    }

    public class calculateTime
    {
        // 添加计算年纪的方法。HFY
        public void GetAgeByBirthday(DateTime birthday, DateTime now, out int year, out int month, out int day)

        {

            //生日的年，月，日
            int birthdayYear = birthday.Year;
            int birthdayMonth = birthday.Month;
            int birthdayDay = birthday.Day;

            //当前时间的年,月,日
            int nowYear = now.Year;
            int nowMonth = now.Month;
            int nowDay = now.Day;

            //得到天
            if (nowDay >= birthdayDay)

            {
                day = nowDay - birthdayDay;
            }
            else
            {
                nowMonth -= 1;
                day = GetDay(nowMonth, nowYear) + nowDay - birthdayDay;
            }

            //得到月

            if (nowMonth >= birthdayMonth)
            {
                month = nowMonth - birthdayMonth;
            }
            else
            {
                nowYear -= 1;
                month = 12 + nowMonth - birthdayMonth;
            }

            //得到年
            year = nowYear - birthdayYear;

        }

        /// 获取天数
        public int GetDay(int month, int year)

        {
            int day = 0;
            switch (month)
            {
                case 1:

                case 3:

                case 5:

                case 7:

                case 8:

                case 10:

                case 12:

                    day = 31;

                    break;

                case 2:

                    //闰年天，平年天

                    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)

                    {
                        day = 29;
                    }
                    else
                    {
                        day = 28;
                    }
                    break;

                case 4:

                case 6:

                case 9:

                case 11:

                    day = 30;

                    break;

            }
            return day;
        }
    }

}
